<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'basic';
$return=array();
/*******basic*******/
if($_RQ['op']=='basic'){
	if($_RQ['postdata']){
		$postdata=get_postdata();
		$this->plugin_setting('basic',$postdata);
		if($postdata['canup'] && $postdata['isuptoken']){
			$this->model('huo_api')->getAccessToken($postdata);
		}
		//$order=pdo_get('jy_weishop_order',array('id'=>'','uniacid'=>$_SESSION['uniacid']));
		//$res=$this->model('huo_api')->order_send($order);
		exi('设置成功');
	}
	$return['item']=$this->plugin_setting('basic');
	$return['item']['canup']=$return['item']['expire']>time()?1:0;
	$account_host=get_account_url();
	$backurl=str_replace('http://','',$account_host).'addons/jy_huolala/auth2.php?i='.$_SESSION['uniacid'];
	$redirect_uri=urlencode($backurl);
	if($return['item']['type']){
		$url="https://open.huolala.cn/#/oauth/authorize?response_type=code&client_id=".$return['item']['app_key']."&redirect_uri=".$redirect_uri."&isSandbox=false";
	}else{
		$url="https://open-pre.huolala.cn/#/oauth/authorize?response_type=code&client_id=".$return['item']['app_key']."&redirect_uri=".$redirect_uri."&isSandbox=true";
	}
	$return['item']['auth2url']=$url;
	$return['item']['backurl']=$backurl;
	$htmls=array(
		'type'=>'edit',
		'desc'=>'参数设置',
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('type'=>'switch','title'=>'是否启用','name'=>'isopen'),
					array('type'=>'radio','title'=>'接入类型','name'=>'type','options'=>'type'),
					array('type'=>'string','title'=>'应用appkey','name'=>'app_key','help'=>'https://open.huolala.cn/注册申请【货拉拉企业版】'),
					array('type'=>'string','title'=>'应用appsecret','name'=>'app_secret'),
					array('type'=>'string','title'=>'城市ID','name'=>'city_id','help'=>'城市列表--复制城市ID'),
					array('type'=>'string','title'=>'车型ID','name'=>'order_vehicle_id','help'=>'可选车型--复制车型ID'),
					array('type'=>'title','title'=>'结算用户授权情况'),
					array('type'=>'copy','title'=>'授权回调地址','name'=>'backurl','help'=>'复制填入：应用-基本信息-授权回调地址。'),
					array('type'=>'copy','title'=>'授权用户账户','name'=>'auth_mobile'),
					array('type'=>'copy','title'=>'令牌过期时间','name'=>'auth_end_time'),
					array('type'=>'switch','title'=>'是否刷新令牌？','name'=>'isuptoken','show'=>array('canup'=>1)),
					array('type'=>'copy','title'=>'OAuth2.0授权','name'=>'auth2url','help'=>'货拉拉用户,在授权页面完成登录授权（沙箱环境的验证码是 6666）。'),
					array('type'=>'ewm','title'=>'OAuth2.0授权','name'=>'auth2url','width'=>300,'show_wxapp_ewm'=>false),
				)
			),
		),
	);
	$return['type']=array('沙箱环境','生产环境');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='auth2'){
	$res=$this->model('huo_api')->gettoken($_RQ['code']);
	exi('success');
}
/*******basic*******/
/*******op*******/
